/*
	Gatherer Content Managment System
	Copyright © 2007-2010 by Eric Hokanson
	Last changed on $LastChangedDate: 2007-08-21 16:19:12 -0600 (Tue, 21 Aug 2007) $
	Revision $Revision: 29 $
	Powered by MooTools v1.2
*/

// Admin menu slide toggle
function enableSlider() {
	$$('a.toggle').addEvent('click', function(el){
			new Fx.Slide(this).toggle();
	});
}

// InlineEdit enable
function enableEdit() {
	$$('p.annotation').each(function(el){
		if (el.get('text') == '')
			el.set('text', '[Add Annotation]');
		el.setStyle('cursor','pointer');
		el.addEvent('click',function(){
			this.inlineEdit({stripHtml:false,
				onComplete:function(el){
					if (this.originalText != this.getContent())
						var myAjax = new Request({ url: 'ajax_dispatcher.php' }).send('mod=news&table=reader&col=annotation&id=' + el.getProperty('id') + '&data=' + encodeURIComponent(this.getContent()));
				}
			});
		});
	});

	$$('.news .story p.content').each(function(el){
		el.setStyle('cursor','pointer');
		el.addEvent('click',function(){
			this.inlineEdit({stripHtml:false,
				onComplete:function(el){
					if (this.originalText != this.getContent())
						var myAjax = new Request({ url: 'ajax_dispatcher.php' }).send('mod=news&table=news&col=content&id=' + el.getProperty('id') + '&data=' + encodeURIComponent(this.getContent()));
				}
			});
		});
	});
}

// Populate dropdown with phpBB3 forum names
function popTopic(path, id) {
	$('phpbbtopic').empty();
	new Request.JSON({url: 'ajax_dispatcher.php', onComplete: function(topic){
		topic.each(function(item){
			if (id && id == item['forum_id'])
				$('phpbbtopic').grab(new Element('option', { value: item['forum_id'], text: item['forum_name'], selected: true }));
			else
				$('phpbbtopic').grab(new Element('option', { value: item['forum_id'], text: item['forum_name'] }));
		});
	}}).send("mod=admin&path=" + path);
}

// Toggle checkboxes based on Published box
function togglePub(checked) {
	if (checked) {
		if (document.forms[0].comments)
			document.forms[0].comments.disabled = false;
		if (document.forms[0].menu)
			document.forms[0].menu.disabled = false;
		if (document.forms[0].sticky)
			document.forms[0].sticky.disabled = false;
	} else {
		if (document.forms[0].comments) {
			document.forms[0].comments.disabled = true;
			document.forms[0].comments.checked = false;
		}
		if (document.forms[0].menu) {
			document.forms[0].menu.disabled = true;
			document.forms[0].menu.checked = false;
		}
		if (document.forms[0].sticky) {
			document.forms[0].sticky.disabled = true;
			document.forms[0].sticky.checked = false;
		}
	}
}

window.addEvent('domready', function() {
    enableEdit();
	new DatePicker('#calendar', { positionOffset: { x: 0, y: 5 }, inputOutputFormat: 'Y-m-d H:i:s', timePicker: true, format: 'Y-m-d H:i:s' });
});
